import 'package:flutter/material.dart';
import 'CheckBoxDemo.dart';
import 'RadioGroupDemo.dart';
import 'SwitchDemo.dart';
import 'SliderDemo.dart';
import 'DateTimeDemo.dart';
import 'AlertDialogDemo.dart';
import 'SampleDialogDemo.dart';
import 'BottomSheetDemo.dart';
import 'SnackBarDemo.dart';
import 'ExpansionPanelDemo.dart';
import 'ChipDemo.dart';

class MaterialComponentDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        title: Text('MaterialComponentDemo'),
      ),
      body: ListView(
        children: <Widget>[
          ListItem(title: 'ExpansionPanelDemo', page: ExpansionPanelDemo()),
          ListItem(title: 'ChipDemo', page: ChipDemo()),
          ListItem(title: 'SnackBarDemo', page: SnackBarDemo()),
          ListItem(title: 'BottomSheetDemo', page: BottomSheetDemo()),
          ListItem(title: 'AlertDialogDemo', page: AlertDialogDemo()),
          ListItem(title: 'SimpleDialogDemo', page: SampleDialogDemo()),
          ListItem(title: 'DateTimeDemo', page: DateTimeDemo()),
          ListItem(title: 'SliderDemo', page: SliderDemo()),
          ListItem(title: 'SwitchDemo', page: SwitchDemo()),
          ListItem(title: 'RadioGroupDemo', page: RadioGroupDemo()),
          ListItem(title: 'checkDemo', page: CheckBoxDemo()),
          ListItem(
              title: 'FloatingActionButtonDemo',
              page: FloatingActionButtonDemo()),
          ListItem(title: 'ButtonDemo', page: ButtonDemo())
        ],
      ),
    );
  }
}

class ButtonDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final flatBtn = Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        FlatButton(
          onPressed: () {},
          splashColor: Colors.grey,
          child: Text(
            'flatButton',
            style: TextStyle(color: Colors.blue),
          ),
          textColor: Theme.of(context).accentColor,
        ),
        FlatButton.icon(
          onPressed: () {},
          label: Text('flatBtnIcon'),
          splashColor: Colors.grey,
          textColor: Theme.of(context).accentColor,
          icon: Icon(Icons.add),
        )
      ],
    );

    final RaisedBtns = Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        RaisedButton(
          onPressed: () {},
          child: Text('RaisedBtn'),
        ),
        SizedBox(
          height: 32.0,
        ),
        RaisedButton.icon(
            onPressed: () {},
            icon: Icon(Icons.access_alarm),
            label: Text('RaistedBtnIcon'))
      ],
    );

    return Scaffold(
      appBar: AppBar(
        title: Text('ButtonDemo'),
      ),
      body: Container(
        margin: EdgeInsets.all(10.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[RaisedBtns],
        ),
      ),
    );
  }
}

class FloatingActionButtonDemo extends StatelessWidget {
  final _FloatingActionButton = FloatingActionButton(
    onPressed: () {},
    shape: CircleBorder(),
    backgroundColor: Colors.green,
    child: Icon(
      Icons.add,
      color: Colors.white,
    ),
    elevation: 0.0,
  );

  final _floatingActionBtnExtend = FloatingActionButton.extended(
      onPressed: () {}, icon: Icon(Icons.add_a_photo), label: Text('添加图片'));

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('FloatingActionButtonDemo'),
        elevation: 0.0,
      ),
      floatingActionButton: _FloatingActionButton,
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        child: Container(
          height: 80.0,
        ),
        shape: CircularNotchedRectangle(), //底部菜单栏的形状为缺口
      ),
    );
  }
}

class ListItem extends StatelessWidget {
  String title;
  Widget page;

  ListItem({this.title, this.page});

  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: Text(this.title),
      onTap: () {
        Navigator.of(context)
            .push(MaterialPageRoute(builder: (context) => page));
      },
    );
  }
}
